Fixes #4851: Prevent apply_diff tool hangs when modifying XML files #4854
+186
−20
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Summary
This PR fixes issue #4852 where the
apply_difftool would hang indefinitely when modifying XML files, particularly during the approval phase after Roo has decided on the change but before the file is written.Root Cause Analysis
The hang was caused by several factors:
parseXml()to parse XML arguments, which could hang indefinitely on complex XML contentChanges Made
1. Safe XML Parsing with Timeout Protection
safeParseXml()function with configurable timeout (default 5 seconds)isProblematicXmlContent()to detect potentially problematic XML patterns2. Improved HTML Entity Handling
3. Regex Timeout Protection
4. Enhanced Error Messages
write_to_filefor extensive changesFiles Modified
src/core/tools/multiApplyDiffTool.ts- Added safe XML parsing and timeout protectionsrc/core/tools/applyDiffTool.ts- Improved HTML entity handling for XML contentsrc/core/diff/strategies/multi-file-search-replace.ts- Added regex timeout protectionsrc/core/diff/strategies/multi-search-replace.ts- Added regex timeout protectionTesting
Impact
This fix ensures that:
Closes #4852
Important
Fixes hanging issue in
apply_difftool for XML files by adding timeout mechanisms and improving error handling.safeParseXml()inmultiApplyDiffTool.tsfor XML parsing with timeout.isProblematicXmlContent()inmultiApplyDiffTool.tsto detect complex XML patterns.multi-file-search-replace.tsandmulti-search-replace.ts.applyDiffTool.tsandmultiApplyDiffTool.ts.multiApplyDiffTool.ts.write_to_filefor extensive changes.multiApplyDiffTool.ts: Safe XML parsing, error handling improvements.applyDiffTool.ts: Improved HTML entity handling.multi-file-search-replace.ts,multi-search-replace.ts: Regex timeout protection.This description was created by
for d7f9a5e. You can customize this summary. It will automatically update as commits are pushed.